package com.king.io;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.common.io.Resources;

/**
 * @author taomk
 * @version 1.0
 * @since 15-1-25 下午10:11
 */
public class FilesTest {

	public static void main(String [] args) throws IOException {

		URL url = Resources.getResource("/test.txt");

		String content = Resources.toString(url, Charsets.UTF_8);

		List<String> lineList = Resources.readLines(url, Charsets.UTF_8);

		byte[] contentArray = Resources.toByteArray(url);

		// 文本文件读取（Guava这么用）
		File file = new File(FilesTest.class.getResource("/test.txt").getFile());
		List<String> lines = null;
		try {
			lines = Files.readLines(file, Charsets.UTF_8);
		} catch (IOException e) {
			e.printStackTrace();
		}

		File textFile = new File("/test.txt");
		String text = Files.toString(textFile, Charsets.UTF_8);

		File binaryFile = new File("/text.png");
		byte[] byteArray = Files.toByteArray(binaryFile);

		Files.write(content, textFile, Charsets.UTF_8);
		Files.write(byteArray, binaryFile);

		File fromFile = new File("/from.txt");
		File toFile = new File("/to.txt");
		Files.copy(fromFile, toFile);
	}
}
